package com.netistate.base;


import java.util.Map;

import com.netistate.pojo.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginValidateInterceptor extends AbstractInterceptor {


	private static final long serialVersionUID = 1L;
	private String goName;
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		String[] nameList = goName.split(",");
		for(String n : nameList){
		}
		
		String actionName = invocation.getProxy().getActionName();
		String nameSpace = invocation.getProxy().getNamespace();
		
		if("/".equals(nameSpace) && ("index".equals(actionName) || ("login".equals(actionName) ))){
			return invocation.invoke();
		}else{
			ActionContext ctx = invocation.getInvocationContext();
			Map<String,Object> session = ctx.getSession();
			if(session.containsKey("session_user")){
				User user = (User) session.get("session_user");
				if(user != null){
					return invocation.invoke();
				}else{
					return "index";
				}
			}else{
				return "index";
			}
		}
	}
	
	public String getGoName() {
		return goName;
	}
	public void setGoName(String goName) {
		this.goName = goName;
	}
}
